using System.Security.Claims;
using PiggyBankCashFlowApi.Exception;

namespace PiggyBankCashFlowApi.Ext;

public static class HttpContextAccessorExt
{
    public static string GetUserId(this IHttpContextAccessor accessor)
    {
        return accessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? throw new JwtNameIdentifierException("Jwt missing user Id.");
    }

    public static string GetUserRole(this IHttpContextAccessor accessor)
    {
        return accessor.HttpContext?.User.FindFirst(ClaimTypes.Role)?.Value ?? throw new JwtRoleException("Jwt missing user role.");
    }
}